const ADD_LIST_ITEM = 'ADD_LIST_ITEM';
const CHANGE_LIST_ID = 'CHANGE_LIST_ID';

const addListItem = (item) => {
  // let item1 = {...item, id: item.id + 1}
  console.log('action')
    return {
      type: ADD_LIST_ITEM,
      payload: item,
    }
};
const changeListId = (id) => {
  return {
    type: CHANGE_LIST_ID,
    listId: id,
  }
}

export const actions = {
  addListItem, changeListId
}

const initialState = {
  list: [],
  listId: null,
};

const reducer = (state = initialState, action) => {
  switch (action.type) {
    case ADD_LIST_ITEM:
      return {...state, list: [...state.list, action.payload]};
    case CHANGE_LIST_ID:
      return {...state, listId: action.listId}
    default:
      return state;
  }

};
export default reducer;
